package com.paulshiyc.imserver.websocket;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
/**
 * WebSocket 配置类
 * @author PaulShi
 *
 */
@Configuration
@EnableWebSocket
public class MyConfig implements WebSocketConfigurer{
	/** 注入自定义处理器*/
	@Autowired
	private MyHandler myHandler;
	/** 注入webSocket处理拦截器 用于扩展*/
	@Autowired
	private WebSocketHandshakeInterceptor webSocketHandshakeInterceptor;
	
	/**
	 * 映射websocket请求路径及添加拦截器扩展
	 */
	@Override
	public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
		registry.addHandler(myHandler, "/im").addInterceptors(webSocketHandshakeInterceptor);
	}

}
